package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @description 说明
 * @package com.sky.controller.admin
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 设置店铺的营业状态
     * @param status
     * @return
     */
    @ApiOperation("设置店铺的营业状态")
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态：{}", status);
        // 设置
        stringRedisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS_KEY,status.toString());
        return Result.success();
    }

    /**
     * 设置店铺的营业状态
     * @return
     */
    @ApiOperation("获取店铺的营业状态")
    @GetMapping("status")
    public Result getShopStatus(){
        // 设置
        String status = stringRedisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS_KEY);
        log.info("获取店铺的营业状态：{}", status);
        return Result.success(Integer.parseInt(status));
    }
}
